﻿using MQTTnet;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace workstation.mqtt
{
    public class MqttMessageAnalyzingProvider
    {
        private Dictionary<String, MqttMessageAnalyzingSetter> s85MessageAnalyzingSetterDictionaries;
        public MqttMessageAnalyzingProvider(List<MqttMessageAnalyzingSetter> abstractFactories)
        {
            s85MessageAnalyzingSetterDictionaries = new Dictionary<string, MqttMessageAnalyzingSetter>();
            foreach (var item in abstractFactories)
            {
                s85MessageAnalyzingSetterDictionaries.Add(item.messageAnalyzingTag(), item);
            }
        }

        public MqttMessageAnalyzingSetter getMqttSetter(string clientTag,string type)
        {
            IEnumerator myEnumerator=s85MessageAnalyzingSetterDictionaries.Values.GetEnumerator();
            while (myEnumerator.MoveNext()) {
                MqttMessageAnalyzingSetter messageAnalyzingSetter = (MqttMessageAnalyzingSetter)myEnumerator.Current;
                /**如果需要比较指令*/
                Boolean topicCompile = messageAnalyzingSetter.typeCompile(clientTag,type);
                if (topicCompile)
                {
                    return messageAnalyzingSetter;
                }
            }
            return null;
        }
    }
}
